//
//  WCG_O_SectonHeaderTableViewCell.m
//  Project_B
//
//  Created by 黑黑 on 15/11/25.
//  Copyright © 2015年 Atom_Wang. All rights reserved.
//

#import "WCG_O_SectonHeaderTableViewCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "UIImage+GIF.h"
@interface WCG_O_SectonHeaderTableViewCell ()

@property (nonatomic, retain) UIView *coverView;

@end

@implementation WCG_O_SectonHeaderTableViewCell
- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubviews];
    }
    return self;
}

- (void)creatSubviews
{
    
    self.mainImage = [[UIImageView alloc] init];
    self.mainImage.contentMode = UIViewContentModeScaleAspectFill;
    self.mainImage.layer.masksToBounds = YES;
    [self.contentView addSubview:self.mainImage];
    
    self.coverView = [[UIView alloc] init];
    self.coverView.backgroundColor = [UIColor blackColor];
    self.coverView.alpha = 0.4;
    [self.contentView addSubview:self.coverView];
    
    self.titleLable = [[UILabel alloc] init];
    self.titleLable.font = [UIFont fontWithName:@"FZSongKeBenXiuKaiS-R-GB" size:18];
    self.titleLable.textColor = [UIColor whiteColor];
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.titleLable];
    
    self.subtitleLable = [[UILabel alloc] init];
    self.subtitleLable.textAlignment = NSTextAlignmentCenter;
    self.subtitleLable.textColor = [UIColor whiteColor];
    self.subtitleLable.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.subtitleLable];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.coverView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height - 5);
    
    [self.mainImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.contentView.frame.size.width);
        make.bottom.mas_equalTo(self.contentView).with.offset(-5);
        make.top.mas_equalTo(self.contentView).with.offset(0);
    }];
    
    
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
    [self.subtitleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.bottom.mas_equalTo(self.mainImage.mas_bottom).with.offset(-10);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
}

- (void)setSpecialModel:(GXSpecialModel *)specialModel
{
    if (_specialModel != specialModel) {
        _specialModel = specialModel;
    }
    // 图片
    [self.mainImage sd_setImageWithURL:_specialModel.thumb[@"raw"] placeholderImage:[UIImage sd_animatedGIFNamed:@"loading"]];
    // 标题
    [self.titleLable setText:_specialModel.title];
    // 副标题
    NSString *temp = [NSString stringWithFormat:@"%@人订阅 | %@篇", _specialModel.subscriber_num, _specialModel.content_num];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:temp];
    NSRange subRange = [temp rangeOfString:[self.specialModel.subscriber_num stringValue]];
    [string addAttributes:@{NSForegroundColorAttributeName : [UIColor yellowColor]} range:subRange];
    NSMutableAttributedString *finalString = [[NSMutableAttributedString alloc] initWithAttributedString:string];
    
    NSRange conRange = [temp rangeOfString:[self.specialModel.content_num stringValue]];
    [finalString addAttributes:@{NSForegroundColorAttributeName : [UIColor yellowColor]} range:conRange];
    
    self.subtitleLable.attributedText = finalString;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
